<?php
// +----------------------------------------------------------------------
// | [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Author < 931274989@qq.com >
// +----------------------------------------------------------------------
// | Explain 洗车
// +----------------------------------------------------------------------
namespace app\ymkj\controller;

use app\model\Order as orderModel;
use think\facade\Session;
use app\model\XicheLog;
use think\Controller;
use think\Db;

 
class Xiche extends Controller
{
  public function index()
  {
    $data = request()->param();
    $xiche = Db::name('xiche')->where('id','=',$data['xid'])->find();
    $this->assign('xiche',$xiche);
    return view();
  }

  public function xiche()
  {
    $data = request()->param();
    $order = new orderModel();
    $jine = Db::name('xiche')->where('id','=',$data['xid'])->value($data['xinghao']);
    $xilog_id = $this->rizhi($data,$jine); // 洗车日志id
    $user = Session::get('wewhat_user');
    $createOrder = $order->save([
      'shop_id' => $data['xid'],
      'openid' => $user['openid'],
      'name' => "会员洗车",
      'jine' => $jine,
      'xid' => $xilog_id
    ]);
    if( $createOrder ){
      //return redirect('Buy/index')->with(['name'=>"会员洗车",'order_id'=>$order->id,'price'=>$jine,'openid'=>$user['openid']]);
      return redirect('Buy/index',array('order_id'=>$order->id));
      //return redirect('Wechat1/save')->with(['name'=>"会员洗车",'order_id'=>$order->id,'price'=>$jine,'openid'=>$user['openid']]);
    } else {
      $this->error('下单失败');
    }
  }

  // 洗车日志
  public function rizhi($data,$jine)
  {
    $model = new XicheLog();
    $user = Session::get('wewhat_user');
    $result = $model->save([
      'xid' => $data['xid'],
      'openid' => $user['openid'],
      'xinghao' => $data['xinghao'],
      'jiner' => $jine,
    ]);
    return $model->id;
  }
}
?>